# $Id$
# Contributor: Ionut Biru <ibiru@archlinux.org>

pkgname=js52
pkgver=52.3.0
pkgrel=1
_ffver=${pkgver%%.*}
pkgdesc="JavaScript interpreter and libraries - Version $_ffver"
arch=(i686 x86_64)
url="https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey"
license=(MPL)
depends=(nspr gcc-libs readline zlib icu libffi)
makedepends=(python2 zip autoconf2.13 mercurial)
_repo=https://hg.mozilla.org/mozilla-unified
source=("hg+$_repo#tag=FIREFOX_${pkgver//./_}esr_RELEASE"
        mozjs52-copy-headers.patch
        mozjs52-disable-mozglue.patch
        mozjs52-fix-soname.patch
        mozjs52-include-configure-script.patch)
sha256sums=('SKIP'
            'c5b3a88e4d10ef149aba6fc48d431db54ff266323fa22a5d549028fd794423cc'
            '5a84f02521f37de873991dd360a4c4bfdbdd2fb4a218e11be73f9cbbf02050e8'
            '06389b8e30465bb8e6fab6144dadedffa30595f143a686524da175b5cf5e8a27'
            'd91a89acd88bfc747a255050757a0c17139bf5c3508c2e1c3c6bb2056786a344')

prepare() {
  cd mozilla-unified

  # https://anonscm.debian.org/git/pkg-gnome/mozjs52.git/tree/debian/patches
  patch -Np1 -i ../mozjs52-fix-soname.patch
  patch -Np1 -i ../mozjs52-copy-headers.patch
  patch -Np1 -i ../mozjs52-disable-mozglue.patch
  patch -Np1 -i ../mozjs52-include-configure-script.patch
}

build() {
  unset CPPFLAGS
  CXXFLAGS+=' -fno-delete-null-pointer-checks -fno-schedule-insns2 -fno-lifetime-dse'
  CFLAGS+=' -fno-delete-null-pointer-checks -fno-schedule-insns2 -fno-lifetime-dse'
  export PYTHON=/usr/bin/python2

  cd mozilla-unified/js/src
  sh configure \
    --prefix=/usr \
    --disable-optimize \
    --enable-ctypes \
    --enable-gcgenerational \
    --enable-pie \
    --enable-readline \
    --enable-shared-js \
    --enable-system-ffi \
    --enable-tests \
    --enable-threadsafe \
    --enable-xterm-updates \
    --with-intl-api \
    --with-system-icu \
    --with-system-nspr \
    --with-system-zlib
  make
}

check() {
  cd mozilla-unified/js/src
  # Intl/Date/toLocaleDateString_timeZone.js:39:5 Error: Assertion failed: got "12/6/2012, UTC", expected "12/6/2012, GMT"
  #make check-jstests
}

package() {
  cd mozilla-unified/js/src
  make DESTDIR="$pkgdir" install
  rm "$pkgdir"/usr/lib/*.ajs
  find "$pkgdir"/usr/{lib/pkgconfig,include} -type f -exec chmod -c a-x {} +
}

# vim:set ts=2 sw=2 et:
